package com.triangle.cashier.widget;


import android.app.Dialog;
import android.app.DialogFragment;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.ImageButton;

import com.triangle.cashier.R;

/**
 * 选择会员
 * Created by  on 2018/6/30.
 */

public class PendingOrderDialog extends DialogFragment implements View.OnClickListener {

    private OnPendingResultClickListener pendingResultClickListener;
    private EditText orderNoteEditText;//挂单备注
    private String orderNum;
    private String note;

    /***
     * @param orderNum                   订单号
     * @param pendingResultClickListener 回调接口
     */
    public PendingOrderDialog(String orderNum, OnPendingResultClickListener pendingResultClickListener) {
        this.orderNum = orderNum;
        this.pendingResultClickListener = pendingResultClickListener;

    }

    public PendingOrderDialog() {
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        View customView = LayoutInflater.from(getActivity()).inflate(
                R.layout.pending_order_dialog, null);
        initView(customView);
        Dialog dialog = new Dialog(getActivity(), R.style.soft_para_dialog);
        dialog.setContentView(customView);
        dialog.setCanceledOnTouchOutside(false);
        Window window = dialog.getWindow();
        window.setGravity(Gravity.CENTER); //可设置dialog的位置
        window.getDecorView().setPadding(0, 0, 0, 0); //消除边距
//        window.setBackgroundDrawable(getResources().getDrawable(R.drawable.shape_windows_bg));
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = 900;   //设置宽度充满屏幕
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(lp);
        return dialog;
    }

    private void initView(View view) {
        orderNoteEditText = view.findViewById(R.id.pending_tip_editText);
        ImageButton closeBtn = view.findViewById(R.id.close_btn);
        closeBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pendingResultClickListener.cancel();
            }
        });

        ImageButton cancelBtn = view.findViewById(R.id.cancel_button);
        cancelBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pendingResultClickListener.cancel();
            }
        });

        ImageButton sureBtn = view.findViewById(R.id.sure_button);
        sureBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                note = orderNoteEditText.getText().toString();
                pendingResultClickListener.ok(orderNum, note);
            }
        });

    }


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public void onStart() {

        super.onStart();
        Window window = this.getDialog().getWindow();
        window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        int uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_IMMERSIVE
                | View.SYSTEM_UI_FLAG_FULLSCREEN;
        window.getDecorView().setSystemUiVisibility(uiOptions);

    }

    @Override
    public void onClick(View v) {

    }

    public interface OnPendingResultClickListener {

        void cancel();

        /**
         * 挂单确认
         *
         * @param orderNum 单号
         * @param note     备注
         */
        void ok(String orderNum, String note);

    }

}
